package com.test14.genericity;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/*
 * 通过泛型得到泛型的对象
 */
public class Test08_Base<T> {
	public T t;
	
	public Test08_Base() {
		try {
			Type type = this.getClass().getGenericSuperclass();
			ParameterizedType parameterizedType = (ParameterizedType) type;

			Type[] types = parameterizedType.getActualTypeArguments();
			Class<T> baseClass = ((Class) types[0]);

			this.t = baseClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}